package controllers

import (
	"fmt"
	"github.com/gin-gonic/gin"
	"k8s-api/kubeclient"
	"net/http"
)

func GetIngressHandler(c *gin.Context) {
	ikc := &kubeclient.IngressKubeController{KubeController: kubeclient.K8sMap["k8s"]}
	namespace := c.Param("namespace")
	application := c.Param("ingress")
	data, err := ikc.Get(namespace, application)
	if err != nil {
		fmt.Println("获取Ingress异常", err)
	}
	c.JSON(http.StatusOK, gin.H{
		"data": data,
	})
}

func CreateIngressHandler(c *gin.Context) {
	ikc := &kubeclient.IngressKubeController{KubeController: kubeclient.K8sMap["k8s"]}
	namespace := c.Param("namespace")
	application := c.Param("ingress")
	domain := c.Param("domain")
	data, err := ikc.Create(namespace, application, domain)
	if err != nil {
		fmt.Println("创建Ingress异常", err)
	}

	c.JSON(http.StatusOK, gin.H{
		"data": data,
	})
}

func DeleteIngressHandler(c *gin.Context) {
	ikc := &kubeclient.IngressKubeController{KubeController: kubeclient.K8sMap["k8s"]}
	namespace := c.Param("namespace")
	application := c.Param("ingress")
	err := ikc.Delete(namespace, application)
	if err != nil {
		fmt.Println("删除Ingress异常", err)
	}
	c.JSON(http.StatusOK, gin.H{
		"data": "ok",
	})
}
